
import os

AsRef = {"width": 1280,
         "height": 720,
         "name": "hd"}

target_dir_rate = {"values": 360.0 / AsRef.get("height"),
                   "values-sw540dp": 540.0 / AsRef.get("height"),
                   "values-sw720dp": 720.0 / AsRef.get("height"),
                   "values-sw1080dp": 1080.0 / AsRef.get("height")}


def genDimen(file, rate):
    file.write('<resources>\n')
    for i in range(1, AsRef.get("width") / 10):
        file.write('\t<dimen name="' + AsRef.get("name") + '_n' + str(i) + '">-' + str(int(round(i * rate))) + 'dp</dimen>\n')
    for i in range(0, AsRef.get("width") + 1):
        file.write('\t<dimen name="' + AsRef.get("name") + '_' + str(i) + '">' + str(int(round(i * rate))) + 'dp</dimen>\n')
    file.write('</resources>\n')

def main():
    for target_dir in target_dir_rate.keys():
        rate = target_dir_rate[target_dir]
        filePath = target_dir + os.sep + 'dimens.xml'
        if not os.path.exists(target_dir):
            os.mkdir(target_dir)
        if os.path.exists(filePath):
            os.remove(filePath)
        f = open(filePath, 'w')
        genDimen(f, rate)


main()
